package com.bytenebula;

import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ByteNebulaException extends RuntimeException {

    public ByteNebulaException() {
        super();
    }

    public ByteNebulaException(ResultCodes code) {
        this(code.getCode(), code.getMessage());
    }

    public ByteNebulaException(ResultCodes code, Object ...args) {
        String message = code.getMessage().formatted(args);
        this.code = code.getCode();
        this.message = message;
    }

    public ByteNebulaException(ResultCodes code, Exception e, Object ...args) {
        String message = code.getMessage().formatted(args);
        this.code = code.getCode();
        this.message = message;
        this.innerException = e;
    }

    public ByteNebulaException(String code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 错误码
     */
    private String code;

    /**
     * 错误信息
     */
    private String message;

    /**
     * 内部异常
     */
    private Exception innerException;
}
